﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_BoardList : System.Web.UI.Page,HZ.MBSM.BLL.IPageDescribe 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strSql, Id;
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            if (!IsPostBack)
            {
                lstExplainState.Items.Add("全部");
                lstExplainState.Items.Add("已答复");
                lstExplainState.Items.Add("未答复");
            }
            if (Request.Form["btnSubmit"] == "删除" && Request.Form["chk"] != null)
            {
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account.Type == "0" || _Account.Type == "1")
                {
                    Id = Request.Form["chk"].ToString();
                    strSql = "delete from board where Id in (" + Id + ")";
                    Db db = new Db();
                    db.Command(strSql);
                    db.Close();

                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "board", strSql, "../Magage/BoardList.aspx");
                }
                else
                {
                    Response.Write("<script>alert('您没有权限删除！');</script>");
                }
            }
            ShowDate();
        }        
    }

    public void ShowDate()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "dbo.Board LEFT OUTER JOIN " +
     " dbo.v_account v_account_1 ON "+
    "  dbo.Board.AnswerId = v_account_1.accountid LEFT OUTER JOIN"+
     " dbo.v_account ON dbo.Board.AccountId = dbo.v_account.accountid";                                               //要查询的表明
        dbPage.Key = "id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "dbo.Board.*, dbo.v_account.DWName AS wname,v_account_1.DWName AS dname,v_account.accountname";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "id";                  //排序字段
        dbPage.OrderByIsDesc = true;
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlLaw.DataSource = dr;
        DlLaw.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string _strTemp = "";
        string _strTitle = txtTitle.Text.ToString().Trim();
        //标题
        if (_strTitle != "")
        {
            _strTemp = " Title like '%" + _strTitle + "%' and";
        }

        //提问人名称
        string _strDWName = txtDWName.Text.ToString().Trim();
        if (_strDWName != "")
        {
            _strTemp += " dbo.v_account.DWName like '%" + _strDWName + "%' and";
        }

        //提问人注册号
        string _strUserCode = txtUserCode.Text.ToString().Trim();
        if (_strUserCode != "")
        {
            _strTemp += " dbo.v_account.UserCode like '%" + _strUserCode + "%' and";
        }

        //答复状态
        string _strExplainState = lstExplainState.SelectedValue;
        switch (_strExplainState)
        {
            case "全部":
                break;
            case "已答复":
                _strTemp += " Explain is not  null and";
                break;
            case "未答复":
                _strTemp += " Explain is  null and";
                break;

        }

        if (_strTemp != "")
        {
            _strTemp = "  " + _strTemp.Substring(0, _strTemp.Length - 3);
        }

        return _strTemp;

    } 

    #region IPageDescribe 成员


    public string Describe
    {
        get { return ""; }
    }
    public string Name
    {
        get { return "问题反馈列表"; }
    }
    public string ParentName
    {
        get { return "问题反馈"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckCompany);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckGoods);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumRquestion);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
            return _AccountType;
        }
    }

    #endregion
}
